from api_tests.base_api import BaseApi

class UserRegisterApi:
    def __init__(self):
        self.api = BaseApi()
        self.url = f"{self.api.base_url}/user/register"
    
    def register_user(self, user_account, user_password, check_password, user_name=None):
        """
        用户注册
        
        Args:
            user_account: 用户账号
            user_password: 用户密码
            check_password: 确认密码
            user_name: 用户名（可选）
            
        Returns:
            str: 格式化的响应结果
        """
        # 构建请求参数
        user_register_request = {
            "userAccount": user_account,
            "userPassword": user_password,
            "checkPassword": check_password
        }
        
        # 添加可选参数
        if user_name:
            user_register_request["userName"] = user_name
        
        # 注册接口不需要认证
        response = self.api.post(
            url=self.url,
            json=user_register_request,
            auth_type="user"
        )
        
        # 解析和格式化响应
        result, error = self.api.parse_response(response)
        return self.api.format_result(result, error)

# 测试示例
if __name__ == "__main__":
    register_api = UserRegisterApi()
    result = register_api.register_user(
        user_account="new_test_user_123",
        user_password="123456",
        check_password="123456",
        user_name="新测试用户"
    )
    print(result)